<script>
export default {
  name:'login',
  mounted() {
    window.localStorage.removeItem("token")
  },
  methods:{
    login(){
      if (this.user.loginName == '' || this.user.password == ''){
        this.$message({
          type: 'error',
          message: '账号密码不能为空!'
        });
        return
      }
      this.$http.post('user/login',this.user).then((resp)=>{
        if (resp.data.code == 200){
          this.$message({
            type: 'success',
            message: '登录成功!'
          });
          localStorage.setItem('token', resp.data.data.token);
          this.$router.push({name:'index'})
        }else {
          this.$message({
            type: 'error',
            message: '账号密码有误!'
          });
        }

      }).catch((error)=>{
        console.log(error)
      })

    }
  },
  data(){
    return{
      //用户数据
      user:{
        loginName:"",
        password:""
      }

    }
  }
}

</script>

<template>

  <div class="container">
    <div class="login-wrapper">
      <div class="header">Login</div>
      <div class="form-wrapper">
        <input type="text" name="username" placeholder="username" class="input-item" v-model="user.loginName">
        <input type="password" name="password" placeholder="password" class="input-item" v-model="user.password">
        <button class="btn" style="border-color: white" @click="login">Login</button>
      </div>
    </div>
  </div>

</template>

<style scoped>
.container {
  height: 100%;
  background-image: linear-gradient(to right, #35a5e1, #e1e8f3);
}
.login-wrapper {
  background-color: #fff;
  width: 358px;
  height: 588px;
  border-radius: 15px;
  padding: 0 50px;
  position: relative;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.header {
  font-size: 38px;
  font-weight: bold;
  text-align: center;
  line-height: 200px;
}
.input-item {
  display: block;
  width: 100%;
  margin-bottom: 20px;
  border: 0;
  padding: 10px;
  border-bottom: 1px solid rgb(128, 125, 125);
  font-size: 15px;
  outline: none;
}
.input-item::placeholder {
  text-transform: uppercase;
}
.btn {
  text-align: center;
  padding: 10px;
  width: 100%;
  margin-top: 40px;
  background-image: linear-gradient(to right, #a6c1ee, #bad7ef);
  color: #fff;
}
.msg {
  text-align: center;
  line-height: 88px;
}
a {
  text-decoration-line: none;
  color: #abc1ee;
}

</style>